<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('菜品信息列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>商品编号：</label>
                            <input type="text" name="goodsSn"/>
                        </li>
                        <li>
                            <label>商品名称：</label>
                            <input type="text" name="name"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()">
                                <i class="fa fa-search"></i>&nbsp;搜索
                            </a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()">
                                <i class="fa fa-refresh"></i>&nbsp;重置
                            </a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="mini:goods:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="mini:goods:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="mini:goods:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="mini:goods:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('mini:goods:edit')}]];
    var removeFlag = [[${@permission.hasPermi('mini:goods:remove')}]];
    var prefix = ctx + "mini/goods";

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "菜品信息",
            columns: [{
                checkbox: true
            },
            {
                field: 'id',
                title: 'id',
                visible: true
            },
            {
                field: 'goodsSn',
                title: '商品编号'
            },
            {
                field: 'name',
                title: '商品名称',
                align: "center",
                width: '10',
                widthUnit: '%',
            },
            {
                field: 'categoryId',
                title: '所属类目ID'
            },
            {
                field: 'picUrl',
                title: '商品图片',
                formatter: function(value, row, index) {
                <!--return $.table.imageView(row.picUrl);-->
                    return "<img style='width: 70px;height: 40px;' src='"+value+"' alt=''>"
                }
            },
            {
                field: 'unit',
                title: '商品单位',
                align: "center"
            },
            {
                field: 'counterPrice',
                title: '专柜价格'
            },
            {
                field: 'retailPrice',
                title: '零售价格'
            },
            {
                field: 'browse',
                title: '浏览量'
            },
            {
                field: 'sales',
                title: '已销售总量'
            },
            {
                field: 'commpany',
                title: '供货单位',
                width: '10',
                widthUnit: '%'
            },
            {
                field: 'wholesalePrice',
                title: '批发价格'
            },
            {
                field: 'isOnSale',
                title: '是否上架',
                align: "center",
                formatter: function(value, item, index) {
                    if (item.isOnSale == 0) {
                        return '<span class="label label-success">否</span>';
                    }
                    else if (item.isOnSale == 1) {
                        return '<span class="label label-primary">是</span>';
                    }
                }
            },
            {
                field: 'isNew',
                title: '是否新品首发',
                align: "center",
                formatter: function(value, item, index) {
                    if (item.isNew == 0) {
                        return '<span class="label label-success">否</span>';
                    }
                    else if (item.isNew == 1) {
                        return '<span class="label label-primary">是</span>';
                    }
                }
            },
            {
                field: 'isHot',
                title: '是否人气推荐',
                align: "center",
                formatter: function(value, item, index) {
                    if (item.isHot == 0) {
                        return '<span class="label label-success">否</span>';
                    }
                    else if (item.isHot == 1) {
                        return '<span class="label label-primary">是</span>';
                    }
                }
            },
            {
                field: 'deleted',
                title: '状态',
                align: "center",
                formatter: function(value, item, index) {
                    /**if (item.deleted == 0) {
                        return '<span class="label label-success">正常</span>';
                    }
                    else if (item.deleted == 1) {
                        return '<span class="label label-danger">删除</span>';
                    */
                    if (item.deleted == 1) {
                        return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + item.id + '\')"></i> ';
                    } else {
                        return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + item.id + '\')"></i> ';
                    }
                }
            },
            {
                title: '操作',
                align: 'center',
                width: '10',
                widthUnit: '%',
                formatter: function(value, row, index) {
                    var actions = [];
                    actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                    actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                    return actions.join('');
                }
            }]
        };
        $.table.init(options);
    });

    /* 菜品管理-停用 */
    function disable(id) {
        $.modal.confirm("确认要停用此菜品吗？", function() {
            $.operate.post(prefix + "/changeStatus", { "id": id, "status": 1 });
        })
    }

    /* 菜品管理-启用 */
    function enable(id) {
        $.modal.confirm("确认要启用此菜品吗？", function() {
            $.operate.post(prefix + "/changeStatus", { "id": id, "status": 0 });
        })
    }


</script>
</body>
</html>